package com.gs.api.projects.shejiao.web;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gs.api.projects.bzapplets.service.BzConfigService;
import com.gs.api.core.Result;
import com.gs.api.projects.shejiao.entity.ManheConfig;
import com.gs.api.projects.shejiao.service.IManheConfigService;
import com.gs.api.projects.weixin.entity.WxAdvert;
import com.gs.api.projects.weixin.service.WxAdvertService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author guoyunfei on 2021/10/9 16:49
 * @className IndexController
 * @description TODO
 * @Version 1.0
 */

@Api(tags = "首页信息加载")
@RestController
@RequestMapping("{appid}/shejiao")
public class IndexController {

    @Autowired
    private WxAdvertService wxAdvertService;

    @Autowired
    private IManheConfigService iManheConfigService;

    @ApiOperation(value = "获取配置信息", notes="获取配置信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "appid", value = "小程序appid", required = true, dataType = "String"),
    })
    @GetMapping("/getConfig")
    public Result getConfig(@PathVariable String appid){
        Map<String,Object> result = new HashMap<>(6);

        ManheConfig manheConfig = iManheConfigService.getOne(new QueryWrapper<ManheConfig>().eq("appid", appid));

        result.put("money",manheConfig.getAccessMoney());
        result.put("isPay",manheConfig.getAccessMode());
        result.put("shenhe",manheConfig.getShenhe());
        result.put("noteShenhe",manheConfig.getNoteShenhe());

        WxAdvert wxAdvert = wxAdvertService.getOne(new LambdaQueryWrapper<WxAdvert>().eq(WxAdvert::getAppid, appid));
        result.put("quid",null != wxAdvert ? wxAdvert.getRewardedVideoid() : null);
        result.put("cunid",null != wxAdvert ? wxAdvert.getRewardedVideoid() : null);
        result.put("adInfo",null != wxAdvert ? wxAdvert : null);

        return Result.success(result);
    }

}
